'\" t
.\"     Title: git-update-index
.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 07/27/2015
.\"    Manual: Git Manual
.\"    Source: Git 2.5.0
.\"  Language: English
.\"
.TH "GIT\-UPDATE\-INDEX" "1" "07/27/2015" "Git 2\&.5\&.0" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-update-index \- Register file contents in the working tree to the index
.SH "SYNOPSIS"
.sp
.nf
\fIgit update\-index\fR
             [\-\-add] [\-\-remove | \-\-force\-remove] [\-\-replace]
             [\-\-refresh] [\-q] [\-\-unmerged] [\-\-ignore\-missing]
             [(\-\-cacheinfo <mode>,<object>,<file>)\&...]
             [\-\-chmod=(+|\-)x]
             [\-\-[no\-]assume\-unchanged]
             [\-\-[no\-]skip\-worktree]
             [\-\-ignore\-submodules]
             [\-\-really\-refresh] [\-\-unresolve] [\-\-again | \-g]
             [\-\-info\-only] [\-\-index\-info]
             [\-z] [\-\-stdin] [\-\-index\-version <n>]
             [\-\-verbose]
             [\-\-] [<file>\&...]
.fi
.sp
.SH "DESCRIPTION"
.sp
Modifies the index or directory cache\&. Each file mentioned is updated into the index and any \fIunmerged\fR or \fIneeds updating\fR state is cleared\&.
.sp
See also \fBgit-add\fR(1) for a more user\-friendly way to do some of the most common operations on the index\&.
.sp
The way \fIgit update\-index\fR handles files it is told about can be modified using the various options:
.SH "OPTIONS"
.PP
\-\-add
.RS 4
If a specified file isn\(cqt in the index already then it\(cqs added\&. Default behaviour is to ignore new files\&.
.RE
.PP
\-\-remove
.RS 4
If a specified file is in the index but is missing then it\(cqs removed\&. Default behavior is to ignore removed file\&.
.RE
.PP
\-\-refresh
.RS 4
Looks at the current index and checks to see if merges or updates are needed by checking stat() information\&.
.RE
.PP
\-q
.RS 4
Quiet\&. If \-\-refresh finds that the index needs an update, the default behavior is to error out\&. This option makes
\fIgit update\-index\fR
continue anyway\&.
.RE
.PP
\-\-ignore\-submodules
.RS 4
Do not try to update submodules\&. This option is only respected when passed before \-\-refresh\&.
.RE
.PP
\-\-unmerged
.RS 4
If \-\-refresh finds unmerged changes in the index, the default behavior is to error out\&. This option makes
\fIgit update\-index\fR
continue anyway\&.
.RE
.PP
\-\-ignore\-missing
.RS 4
Ignores missing files during a \-\-refresh
.RE
.PP
\-\-cacheinfo <mode>,<object>,<path>, \-\-cacheinfo <mode> <object> <path>
.RS 4
Directly insert the specified info into the index\&. For backward compatibility, you can also give these three arguments as three separate parameters, but new users are encouraged to use a single\-parameter form\&.
.RE
.PP
\-\-index\-info
.RS 4
Read index information from stdin\&.
.RE
.PP
\-\-chmod=(+|\-)x
.RS 4
Set the execute permissions on the updated files\&.
.RE
.PP
\-\-[no\-]assume\-unchanged
.RS 4
When this flag is specified, the object names recorded for the paths are not updated\&. Instead, this option sets/unsets the "assume unchanged" bit for the paths\&. When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index\&. If you want to change the working tree file, you need to unset the bit to tell Git\&. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e\&.g\&. cifs)\&.
.sp
Git will fail (gracefully) in case it needs to modify this file in the index e\&.g\&. when merging in a commit; thus, in case the assumed\-untracked file is changed upstream, you will need to handle the situation manually\&.
.RE
.PP
\-\-really\-refresh
.RS 4
Like
\fI\-\-refresh\fR, but checks stat information unconditionally, without regard to the "assume unchanged" setting\&.
.RE
.PP
\-\-[no\-]skip\-worktree
.RS 4
When one of these flags is specified, the object name recorded for the paths are not updated\&. Instead, these options set and unset the "skip\-worktree" bit for the paths\&. See section "Skip\-worktree bit" below for more information\&.
.RE
.PP
\-g, \-\-again
.RS 4
Runs
\fIgit update\-index\fR
itself on the paths whose index entries are different from those from the
HEAD
commit\&.
.RE
.PP
\-\-unresolve
.RS 4
Restores the
\fIunmerged\fR
or
\fIneeds updating\fR
state of a file during a merge if it was cleared by accident\&.
.RE
.PP
\-\-info\-only
.RS 4
Do not create objects in the object database for all <file> arguments that follow this flag; just insert their object IDs into the index\&.
.RE
.PP
\-\-force\-remove
.RS 4
Remove the file from the index even when the working directory still has such a file\&. (Implies \-\-remove\&.)
.RE
.PP
\-\-replace
.RS 4
By default, when a file
path
exists in the index,
\fIgit update\-index\fR
refuses an attempt to add
path/file\&. Similarly if a file
path/file
exists, a file
path
cannot be added\&. With \-\-replace flag, existing entries that conflict with the entry being added are automatically removed with warning messages\&.
.RE
.PP
\-\-stdin
.RS 4
Instead of taking list of paths from the command line, read list of paths from the standard input\&. Paths are separated by LF (i\&.e\&. one path per line) by default\&.
.RE
.PP
\-\-verbose
.RS 4
Report what is being added and removed from index\&.
.RE
.PP
\-\-index\-version <n>
.RS 4
Write the resulting index out in the named on\-disk format version\&. Supported versions are 2, 3 and 4\&. The current default version is 2 or 3, depending on whether extra features are used, such as
git add \-N\&.
.sp
Version 4 performs a simple pathname compression that reduces index size by 30%\-50% on large repositories, which results in faster load time\&. Version 4 is relatively young (first released in in 1\&.8\&.0 in October 2012)\&. Other Git implementations such as JGit and libgit2 may not support it yet\&.
.RE
.PP
\-z
.RS 4
Only meaningful with
\-\-stdin
or
\-\-index\-info; paths are separated with NUL character instead of LF\&.
.RE
.PP
\-\-split\-index, \-\-no\-split\-index
.RS 4
Enable or disable split index mode\&. If enabled, the index is split into two files, $GIT_DIR/index and $GIT_DIR/sharedindex\&.<SHA\-1>\&. Changes are accumulated in $GIT_DIR/index while the shared index file contains all index entries stays unchanged\&. If split\-index mode is already enabled and
\-\-split\-index
is given again, all changes in $GIT_DIR/index are pushed back to the shared index file\&. This mode is designed for very large indexes that take a significant amount of time to read or write\&.
.RE
.PP
\-\-untracked\-cache, \-\-no\-untracked\-cache
.RS 4
Enable or disable untracked cache extension\&. This could speed up for commands that involve determining untracked files such as
git status\&. The underlying operating system and file system must change
st_mtime
field of a directory if files are added or deleted in that directory\&.
.RE
.PP
\-\-force\-untracked\-cache
.RS 4
For safety,
\-\-untracked\-cache
performs tests on the working directory to make sure untracked cache can be used\&. These tests can take a few seconds\&.
\-\-force\-untracked\-cache
can be used to skip the tests\&.
.RE
.PP
\-\-
.RS 4
Do not interpret any more arguments as options\&.
.RE
.PP
<file>
.RS 4
Files to act on\&. Note that files beginning with
\fI\&.\fR
are discarded\&. This includes
\&./file
and
dir/\&./file\&. If you don\(cqt want this, then use cleaner names\&. The same applies to directories ending
\fI/\fR
and paths with
\fI//\fR
.RE
.SH "USING --REFRESH"
.sp
\fI\-\-refresh\fR does not calculate a new sha1 file or bring the index up\-to\-date for mode/content changes\&. But what it \fBdoes\fR do is to "re\-match" the stat information of a file with the index, so that you can refresh the index for a file that hasn\(cqt been changed but where the stat entry is out of date\&.
.sp
For example, you\(cqd want to do this after doing a \fIgit read\-tree\fR, to link up the stat index details with the proper files\&.
.SH "USING --CACHEINFO OR --INFO-ONLY"
.sp
\fI\-\-cacheinfo\fR is used to register a file that is not in the current working directory\&. This is useful for minimum\-checkout merging\&.
.sp
To pretend you have a file with mode and sha1 at path, say:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git update\-index \-\-cacheinfo <mode>,<sha1>,<path>
.fi
.if n \{\
.RE
.\}
.sp
.sp
\fI\-\-info\-only\fR is used to register files without placing them in the object database\&. This is useful for status\-only repositories\&.
.sp
Both \fI\-\-cacheinfo\fR and \fI\-\-info\-only\fR behave similarly: the index is updated but the object database isn\(cqt\&. \fI\-\-cacheinfo\fR is useful when the object is in the database but the file isn\(cqt available locally\&. \fI\-\-info\-only\fR is useful when the file is available, but you do not wish to update the object database\&.
.SH "USING --INDEX-INFO"
.sp
\-\-index\-info is a more powerful mechanism that lets you feed multiple entry definitions from the standard input, and designed specifically for scripts\&. It can take inputs of three formats:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
mode SP sha1 TAB path
.sp
The first format is what "git\-apply \-\-index\-info" reports, and used to reconstruct a partial tree that is used for phony merge base tree when falling back on 3\-way merge\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
mode SP type SP sha1 TAB path
.sp
The second format is to stuff
\fIgit ls\-tree\fR
output into the index file\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 3.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  3." 4.2
.\}
mode SP sha1 SP stage TAB path
.sp
This format is to put higher order stages into the index file and matches
\fIgit ls\-files \-\-stage\fR
output\&.
.RE
.sp
To place a higher stage entry to the index, the path should first be removed by feeding a mode=0 entry for the path, and then feeding necessary input lines in the third format\&.
.sp
For example, starting with this index:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git ls\-files \-s
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0       frotz
.fi
.if n \{\
.RE
.\}
.sp
.sp
you can feed the following input to \-\-index\-info:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git update\-index \-\-index\-info
0 0000000000000000000000000000000000000000      frotz
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
.fi
.if n \{\
.RE
.\}
.sp
.sp
The first line of the input feeds 0 as the mode to remove the path; the SHA\-1 does not matter as long as it is well formatted\&. Then the second and third line feeds stage 1 and stage 2 entries for that path\&. After the above, we would end up with this:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git ls\-files \-s
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz
.fi
.if n \{\
.RE
.\}
.sp
.SH "USING \(lqASSUME UNCHANGED\(rq BIT"
.sp
Many operations in Git depend on your filesystem to have an efficient lstat(2) implementation, so that st_mtime information for working tree files can be cheaply checked to see if the file contents have changed from the version recorded in the index file\&. Unfortunately, some filesystems have inefficient lstat(2)\&. If your filesystem is one of them, you can set "assume unchanged" bit to paths you have not changed to cause Git not to do this check\&. Note that setting this bit on a path does not mean Git will check the contents of the file to see if it has changed \(em it makes Git to omit any checking and assume it has \fBnot\fR changed\&. When you make changes to working tree files, you have to explicitly tell Git about it by dropping "assume unchanged" bit, either before or after you modify them\&.
.sp
In order to set "assume unchanged" bit, use \-\-assume\-unchanged option\&. To unset, use \-\-no\-assume\-unchanged\&. To see which files have the "assume unchanged" bit set, use git ls\-files \-v (see \fBgit-ls-files\fR(1))\&.
.sp
The command looks at core\&.ignorestat configuration variable\&. When this is true, paths updated with git update\-index paths\&.\&.\&. and paths updated with other Git commands that update both index and working tree (e\&.g\&. \fIgit apply \-\-index\fR, \fIgit checkout\-index \-u\fR, and \fIgit read\-tree \-u\fR) are automatically marked as "assume unchanged"\&. Note that "assume unchanged" bit is \fBnot\fR set if git update\-index \-\-refresh finds the working tree file matches the index (use git update\-index \-\-really\-refresh if you want to mark them as "assume unchanged")\&.
.SH "EXAMPLES"
.sp
To update and refresh only the files already checked out:
.sp
.if n \{\
.RS 4
.\}
.nf
$ git checkout\-index \-n \-f \-a && git update\-index \-\-ignore\-missing \-\-refresh
.fi
.if n \{\
.RE
.\}
.sp

.PP
On an inefficient filesystem with core\&.ignorestat set
.RS 4
.sp
.if n \{\
.RS 4
.\}
.nf
$ git update\-index \-\-really\-refresh              \fB(1)\fR
$ git update\-index \-\-no\-assume\-unchanged foo\&.c   \fB(2)\fR
$ git diff \-\-name\-only                           \fB(3)\fR
$ edit foo\&.c
$ git diff \-\-name\-only                           \fB(4)\fR
M foo\&.c
$ git update\-index foo\&.c                         \fB(5)\fR
$ git diff \-\-name\-only                           \fB(6)\fR
$ edit foo\&.c
$ git diff \-\-name\-only                           \fB(7)\fR
$ git update\-index \-\-no\-assume\-unchanged foo\&.c   \fB(8)\fR
$ git diff \-\-name\-only                           \fB(9)\fR
M foo\&.c
.fi
.if n \{\
.RE
.\}
.sp
\fB1. \fRforces lstat(2) to set "assume unchanged" bits for paths that match index\&.
.br
\fB2. \fRmark the path to be edited\&.
.br
\fB3. \fRthis does lstat(2) and finds index matches the path\&.
.br
\fB4. \fRthis does lstat(2) and finds index does
\fBnot\fR
match the path\&.
.br
\fB5. \fRregistering the new version to index sets "assume unchanged" bit\&.
.br
\fB6. \fRand it is assumed unchanged\&.
.br
\fB7. \fReven after you edit it\&.
.br
\fB8. \fRyou can tell about the change after the fact\&.
.br
\fB9. \fRnow it checks with lstat(2) and finds it has been changed\&.
.br
.RE
.SH "SKIP-WORKTREE BIT"
.sp
Skip\-worktree bit can be defined in one (long) sentence: When reading an entry, if it is marked as skip\-worktree, then Git pretends its working directory version is up to date and read the index version instead\&.
.sp
To elaborate, "reading" means checking for file existence, reading file attributes or file content\&. The working directory version may be present or absent\&. If present, its content may match against the index version or not\&. Writing is not affected by this bit, content safety is still first priority\&. Note that Git \fIcan\fR update working directory file, that is marked skip\-worktree, if it is safe to do so (i\&.e\&. working directory version matches index version)
.sp
Although this bit looks similar to assume\-unchanged bit, its goal is different from assume\-unchanged bit\(cqs\&. Skip\-worktree also takes precedence over assume\-unchanged bit when both are set\&.
.SH "CONFIGURATION"
.sp
The command honors core\&.filemode configuration variable\&. If your repository is on a filesystem whose executable bits are unreliable, this should be set to \fIfalse\fR (see \fBgit-config\fR(1))\&. This causes the command to ignore differences in file modes recorded in the index and the file mode on the filesystem if they differ only on executable bit\&. On such an unfortunate filesystem, you may need to use \fIgit update\-index \-\-chmod=\fR\&.
.sp
Quite similarly, if core\&.symlinks configuration variable is set to \fIfalse\fR (see \fBgit-config\fR(1)), symbolic links are checked out as plain files, and this command does not modify a recorded file mode from symbolic link to regular file\&.
.sp
The command looks at core\&.ignorestat configuration variable\&. See \fIUsing "assume unchanged" bit\fR section above\&.
.sp
The command also looks at core\&.trustctime configuration variable\&. It can be useful when the inode change time is regularly modified by something outside Git (file system crawlers and backup systems use ctime for marking files processed) (see \fBgit-config\fR(1))\&.
.SH "SEE ALSO"
.sp
\fBgit-config\fR(1), \fBgit-add\fR(1), \fBgit-ls-files\fR(1)
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite
